#
# Created: 2025-08-11

import pandas as pd
import plotly.graph_objects as go

# ======================
# 配色（线色与填充色一一对应）
# ======================
colors = ["#4f7942", "#c65f0a", "#a03530", "#5e4c8c", "#20648a"]
fill_colors = ["#b0d1a6", "#f5c5a0", "#e7a39a", "#b1a5c9", "#a0d8ef"]

DATA_CSV = "data.csv"

# ======================
# 1) 从本地读取并绘图
# ======================
data_df = pd.read_csv(DATA_CSV)

fig = go.Figure()

x_data = list(data_df.columns)
y_data = [data_df[col].values for col in data_df.columns]

for xd, yd, cls, fcls in zip(x_data, y_data, colors, fill_colors):
    fig.add_trace(
        go.Box(
            y=yd,
            name=xd,
            boxpoints="all",
            width=0.2,
            whiskerwidth=0.4,
            jitter=1,
            pointpos=-2.0,
            fillcolor=fcls,
            line_width=2,
            line_color=cls,
            marker_color=fcls,
            marker_size=8,
            marker_line_color=cls,
            marker_line_width=2,
            opacity=0.4

        )
    )

fig.update_layout(
    yaxis=dict(title="Y值"),
    width=800,
    height=500,
    showlegend=False,
    template="plotly_white",           # 干净白底；如需透明可改为 None，并设置 paper/plot_bgcolor 为透明
)
fig.write_html("箱线图.html")
fig.show()
